{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 类"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`__init__()` 是构造函数，初始化对象时调用。参数列表中的第一个参数必须是 `self`，因为 Python 中没有 `this` 指针，但是有 `self` 引用，都是指向对象本身。\n",
    "类名 `Student` 后面可以带参数，也可以不带参数。在本例中，没有带参数，但是不影响初始化是给它传参，因为 `__init__()` 函数才是构造函数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hi! I'm jim\n",
      "my grade is: 86\n",
      "hi! I'm jim\n",
      "my grade is: 96\n"
     ]
    }
   ],
   "source": [
    "class Student:\n",
    "    def __init__(self, name, grade):\n",
    "        self.name = name\n",
    "        self.grade = grade\n",
    "\n",
    "    def introduce(self):\n",
    "        print(\"hi! I'm \" + self.name)\n",
    "        print(\"my grade is: \" + str(self.grade))\n",
    "\n",
    "    def improve(self, amount):\n",
    "        self.grade = self.grade + amount\n",
    "\n",
    "jim = Student(\"jim\", 86)\n",
    "jim.introduce()\n",
    "\n",
    "jim.improve(10)\n",
    "jim.introduce()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
